import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
import { Document } from 'mongoose'
import { TemplateParams } from './workflow-template.schema'

@Schema({ timestamps: true })
export class TemplateVersion extends Document {
    @Prop({ required: true })
    templateId: string

    @Prop({ required: true })
    version: string

    @Prop({ type: Object, required: true })
    workflow: any

    @Prop({ type: Object, required: true })
    defaultParams: TemplateParams

    @Prop({ required: true })
    changeLog: string

    @Prop({ required: true })
    author: string

    @Prop({ type: Date, default: Date.now })
    createdAt: Date
}

export const TemplateVersionSchema = SchemaFactory.createForClass(TemplateVersion)

// 添加索引以优化查询性能
TemplateVersionSchema.index({ templateId: 1, version: 1 }, { unique: true })
TemplateVersionSchema.index({ templateId: 1, createdAt: -1 })